/*
 * IAnimationController.cpp
 *
 *  Created on: 05.01.2012
 *      Author: Kirill Blinov
 *      Copyright: LGPL
 */

#include "CAnimationController.h"

CAnimationController::CAnimationController( std::vector<CBasicAnimation> &AnimationArray, IPhysicsObject* PhysicsObject ):
                                            animationArray(AnimationArray), physicsObject(PhysicsObject)
{
    if ( animationArray.size() == 0 )
    {
    	throw std::exception();
    }
}

CAnimationController::~CAnimationController()
{
	PhysicObjectFabric::DeletePhysicsObject( physicsObject );
}

bool
CAnimationController::ReplaceAnimation( CBasicAnimation &NewAnimation )
{
	bool result = false;

	CBasicAnimation* FoundAnimation = FindAnimationByName( NewAnimation.GetName() );

    if ( NULL != FoundAnimation )
	{
		*FoundAnimation = NewAnimation;
		result = true;
	}
	return result;
}

IAnimationInterface*
CAnimationController::GetAnimationInterfaceByName( std::string AnimationName )
{
	CBasicAnimation* FoundAnimation = FindAnimationByName( AnimationName );
	return dynamic_cast<FoundAnimation*>( FoundAnimation );
}

IAnimationState*
CAnimationController::GetAnimationStateByName( std::string AnimationName )
{
	CBasicAnimation* FoundAnimation = FindAnimationByName( AnimationName );
	return dynamic_cast<IAnimationState*>( FoundAnimation );
}

CBasicAnimation*
CAnimationController::FindAnimationByName( std::string Name )
{
	CBasicAnimation* Result = NULL;

	for ( std::vector<CBasicAnimation>::iterator StartIt = animationArray.begin(), EndIt = animationArray.end();
		  StartIt != EndIt; StartIt++ )
	{
		if ( Name.compare( StartIt.base()->GetName() ) == 0 )
		{
			Result = StartIt.base();
			break;
		}
	}

	return Result;
}

void
CAnimationController::PlayAnimations( IAnimationPlayer* AnimationPlayer )
{
	for ( std::vector<CBasicAnimation>::iterator BeginIt = animationArray.begin(), EndIt = animationArray.end();
			BeginIt != EndIt; BeginIt++ )
	{
		CBasicAnimation* Animation = BeginIt.base();
		Animation
	}
}

glm::mat4
CAnimationController::GetObjectWorldPosition()
{

}
